package com.yingxin.yx.framework.commons.helper;


import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;


/**
 * @author fanchao
 */
public class MapHelper {

    public static Map<String, Object> objectToMap(Object object) throws IllegalAccessException {
        Map<String, Object> map = new HashMap<String, Object>();
        if (object == null) {
            return map;
        }
        Class clazz = object.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            if (field.get(object) != null) {
                map.put(field.getName(), field.get(object));
            }
        }
        return map;
    }

}
